#include "timer_test.h"

void Timer_test::start(std::chrono::milliseconds interval, std::function<void()> callback)
{
    isRunning = true;
    workerThread = std::thread([this, interval, callback]() {
        while (isRunning) {
            std::this_thread::sleep_for(interval);
            if (isRunning) {
                callback(); // 执行回调函数
            }
        }
    });
}

void Timer_test::stop()
{

    isRunning = false;
    if (workerThread.joinable())
    {
        workerThread.join();
    }

}

Timer_test::~Timer_test() {
    stop(); //在析构时停止定时器
}
